package sz.szsmk.citizencard.ui.fragment;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.BusHomeSiteNearViewBinding;
import sz.szsmk.citizencard.ioc.Compontent.DaggerCommonFragmentComponent;
import sz.szsmk.citizencard.model.network.bean.response.QueryNearStandbyRes;
import sz.szsmk.citizencard.mvp.contract.IBusSiteNearbyContact;
import sz.szsmk.citizencard.mvp.presenter.BusSiteNearbyPresenter;
import sz.szsmk.citizencard.ui.adapter.BusSiteNearbyAdapter;
import sz.szsmk.citizencard.ui.base.IBaseFragment;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/11/15 20:09
 * description:
 */
public class  BusHomeSiteNearFragment extends IBaseFragment<BusSiteNearbyPresenter, BusHomeSiteNearViewBinding>
        implements IBusSiteNearbyContact.IBusSiteNearbyView  {


    private BusSiteNearbyAdapter busSiteNearbyAdapter;

    public static BusHomeSiteNearFragment getInstance() {
        BusHomeSiteNearFragment sf = new BusHomeSiteNearFragment();
        return sf;
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.bus_home_site_near_view;
    }

    @Override
    protected void initInjector() {
        DaggerCommonFragmentComponent.builder().appCompontent(DaggerApplication.getAppComponent())
                .build().inject(this);

    }

    @Override
    protected void initViews() {

        busSiteNearbyAdapter = new BusSiteNearbyAdapter(getActivity());
        dataBinding.collecNearRv.setLayoutManager(new LinearLayoutManager(getContext()));
        dataBinding.collecNearRv.setAdapter(busSiteNearbyAdapter);

        dataBinding.swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                mPresenter.getDataList("string","string");
            }
        });

        dataBinding.swipeRefreshLayout.autoRefresh();

    }

    @Override
    protected void updateViews() {

    }

    @Override
    public void getDataListSucc(QueryNearStandbyRes response) {
        busSiteNearbyAdapter.setViewData(response.getBusSiteList());
        busSiteNearbyAdapter.notifyDataSetChanged();
        //完成加载并标记没有更多数据
        dataBinding.swipeRefreshLayout.finishLoadMoreWithNoMoreData();
    }

    @Override
    public void getDataListFail() {
    }

}
